﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ValidationFramework;
using ValidationFramework.Validators;
using QSAspMvc.Models;
using ValidationFramework.Web.MVC;
using ValidationFramework.Validators.Web.Mvc;
using ValidationFramework.Specifications;

namespace QSAspMvc
{
	public class ValidationBootStrapper
	{
		public static void Boot()
		{
			InitValidationCore();
			InitClientValidation();
		}

		private static void InitValidationCore()
		{
			Validation.Initialize();

			Validation.ConfigurePolicyFor<Product>(x => 
			{
				x.Ensure(y => y.ProductName)
					.Passes(new IsRequiredStringSpec("Dane", false, true))
					.OnFailure()
						.UseMessage("Product name is required. It also can't be 'Dane'");

				x.Ensure(y => y.ReorderLevel)
					.IsPresent()
						.AndIsNot(0)
					.OnFailure()
						.UseMessage("Reorder level is required. Make sure its been changed from default value of '0'");
			});
		}
		private static void InitClientValidation()
		{
			ClientValidation.Initialize(x =>
			{
				// this will register all the client function call providers for the validation framework's included validators
				IncludedValidators.RegisterScriptProviders(x);
			});
		}
	}
}
